import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/refresh")
public class RefreshServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat
                ("yyyy-MM-dd HH:mm:ss");//格式不能改 特定的表示时间
        String format = simpleDateFormat.format(new Date());//用 new Date() 获取当前时间然后转化成字符串
        resp.setHeader("refresh", "1");  // 每秒刷新页面
        resp.setContentType("text/plain; charset=UTF-8");  // 设置内容类型和字符集
        resp.getWriter().write("Current time: " + format);
    }
}

